//BY: Rickyman35

SWEP.Author = "Rickster" 
SWEP.Contact = "" 
SWEP.Purpose = "" 
SWEP.Instructions = "" 
SWEP.Spawnable = false 
SWEP.AdminSpawnable = true 
SWEP.ViewModel = "models/weapons/v_shot_m3super90.mdl" 
SWEP.WorldModel = "models/weapons/w_shot_m3super90.mdl" 
SWEP.Primary.ClipSize = 4
SWEP.Primary.DefaultClip = 4  
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = buckshot 
SWEP.Secondary.ClipSize = -1  
SWEP.Secondary.DefaultClip = -1 
SWEP.Secondary.Automatic = false 
SWEP.Secondary.Ammo = "none" 



local ShootSound = Sound ("Weapon_m249.Single"); 

function SWEP:Reload()
	

	
	// Already reloading
	if ( self.Weapon:GetNetworkedBool( "reloading", true ) ) then return end
	
	// Start reloading if we can
	if ( self.Weapon:Clip1() < self.Primary.ClipSize && self.Owner:GetAmmoCount( self.Primary.Ammo ) > 0 ) then
		
		self.Weapon:SetNetworkedBool( "reloading", true )
		self.Weapon:SetVar( "reloadtimer", CurTime() + 0.3 )
		self.Weapon:SendWeaponAnim( ACT_VM_RELOAD )
		
	end

end


 
function SWEP:throw_attack () 


local tr2 = self.Owner:GetEyeTrace(); 



self.Weapon:EmitSound (ShootSound); 
self.BaseClass.ShootEffects (self); 

if (!SERVER) then return end; 







 ent2 = ents.Create ("smoke"); 

//seems to work for the models I have tried 
ent2:SetPos (self.Owner:EyePos() + (self.Owner:GetAimVector() * 16)); 
ent2:SetAngles (self.Owner:EyeAngles()); 
ent2:Spawn(); 

//Now we need to get the physics object for our entity so we can apply a force to it 

local phys2 = ent2:GetPhysicsObject(); 

//Time to apply the force. My method for doing this was almost entirely empirical 

//and it seems to work fairly intuitively with chairs. 

local shot_length2 = tr2.HitPos:Length(); 

phys2:ApplyForceCenter (self.Owner:GetAimVector():GetNormalized() * math.pow (shot_length2, 1)); 

  
local function FX( pos )

	local effectdata = EffectData()
		effectdata:SetOrigin( pos )
		effectdata:SetMagnitude( 10 )
		effectdata:SetScale( 10 )
		effectdata:SetRadius( 20 )
	util.Effect( "Sparks", effectdata )

end





end 




function SWEP:PrimaryAttack() 
if ( !self:CanPrimaryAttack() ) then return end

self:throw_attack ( ); 

		self.Weapon:SetNextPrimaryFire( CurTime() + 1.5 )
		
		self:TakePrimaryAmmo( 1 )

end  


function SWEP:Think()


	if ( self.Weapon:GetNetworkedBool( "reloading", false ) ) then
	
		if ( self.Weapon:GetVar( "reloadtimer", 0 ) < CurTime() ) then
			
			// Finsished reload -
			if ( self.Weapon:Clip1() >= self.Primary.ClipSize || self.Owner:GetAmmoCount( self.Primary.Ammo ) <= 0 ) then
				self.Weapon:SetNetworkedBool( "reloading", false )
				return
			end
			
			// Next cycle
			self.Weapon:SetVar( "reloadtimer", CurTime() + 0.3 )
			self.Weapon:SendWeaponAnim( ACT_VM_RELOAD )
			
			// Add ammo
			self.Owner:RemoveAmmo( 1, self.Primary.Ammo, false )
			self.Weapon:SetClip1(  self.Weapon:Clip1() + 1 )
			
			// Finish filling, final pump
			if ( self.Weapon:Clip1() >= self.Primary.ClipSize || self.Owner:GetAmmoCount( self.Primary.Ammo ) <= 0 ) then
				self.Weapon:SendWeaponAnim( ACT_SHOTGUN_RELOAD_FINISH )
			else
			
			end
			
		end
	
	end

end